<?php
include_once ("XML/Serializer.php");

// include class file
if(class_exists("XML_Serializer")){

	/**
	 * Class that Model classes inherit to make them serializable
	 *
	 */
	abstract class XML_Serializable {
		/**
		 * The name to use for the root variable
		 * @var string
		 */
		protected $className;

		/**
		 * Serializes the object into XML
		 *
		 * @return string An XML version of this class
		 */
		function getSerializedXML() {
			// An array of serializer options
			$serializer_options = array (XML_SERIALIZER_OPTION_INDENT => '	', XML_SERIALIZER_OPTION_TYPEHINTS => TRUE, XML_SERIALIZER_OPTION_DEFAULT_TAG => 'array_item' );
			// create object
			$serializer = new XML_Serializer ( $serializer_options );
			$status = $serializer->serialize ( $this );
			if (PEAR::isError ( $status )) {
				throw new Exception ( $status->getMessage () );
			}

			return $serializer->getSerializedData ();
		}

	}

}

else{
	
	/**
	 * A stub to warn people that serialization is not available
	 */
	abstract class XML_Serializable {
		/**
		 * The name to use for the root variable
		 * @var string
		 */
		protected $className;

		/**
		 * throws a serialization exception
		 */
		function getSerializedXML() {
			throw new Exception ( "<error>Your server does not include the XML/Serializer.php PEAR class. Please setup this PEAR extension on your server and regenerate your classes to make XML serialization available.</error>");
		}

	}

}

?>